package com.ogawa.joypal.user.widget;

import android.annotation.SuppressLint;
import android.content.Context;
import android.graphics.Color;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;


import com.google.android.material.bottomsheet.BottomSheetDialog;
import com.ogawa.joypal.user.R;


/**
 * 身高/体重选择弹窗
 */
public class ValuePickDialog extends BottomSheetDialog {
    private NumberPickerView npv;
    private TextView tvSave;
    private String[] values;
    public static final int WEIGHT = 0;
    public static final int HEIGHT = 1;
    public static final int GENDER = 2;
    public static final int SUFFER = 3;


    @SuppressLint("SetTextI18n")
    public ValuePickDialog(@NonNull Context context, int type) {
        super(context);
        setContentView(R.layout.dialog_value_pick);
        FrameLayout bottomSheet = (FrameLayout) getDelegate().findViewById(R.id.design_bottom_sheet);
        bottomSheet.setBackgroundColor(Color.TRANSPARENT);
        npv = findViewById(R.id.npv_value);
        tvSave = findViewById(R.id.tv_save);
        TextView tvUnit = findViewById(R.id.tv_unit);
        findViewById(R.id.tv_cancel).setOnClickListener(view -> dismiss());
        switch (type) {
            case WEIGHT:
                values = getContext().getResources().getStringArray(R.array.array_weight);
                tvUnit.setText(R.string.weight_unit);
                break;
            case HEIGHT:
                values = getContext().getResources().getStringArray(R.array.array_height);
                tvUnit.setText(R.string.height_unit);
                break;
            case GENDER:
                values = new String[]{getContext().getString(R.string.male), getContext().getString(R.string.female)};
                break;
            case SUFFER:
                values = new String[]{getContext().getString(R.string.tolerance_light), getContext().getString(R.string.tolerance_medium), getContext().getString(R.string.tolerance_heavy)};
                break;
        }
        npv.setDisplayedValues(values);
        npv.setMinValue(0);
        npv.setMaxValue(values.length - 1);
        npv.setValue(0);
    }

    public void setTvSaveOnClickListener(View.OnClickListener listener) {
        tvSave.setOnClickListener(listener);
    }

    public String getValue() {
        return values[npv.getValue()];
    }

    public int getValueIndex() {
        return npv.getValue();
    }
}
